Loading   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A componentWillReceiveProps 0 7 3
A render 0 3 2
1
import React from 'react';
2
import PropTypes from 'prop-types';
3
4
export default class Loading extends React.Component {
5
  constructor(props) {
6
    super(props);
7
    this.state = {
8
      style: { display: 'none' },
9
    };
10
  }
11
12
  componentWillReceiveProps(newProps) {
13
    if (newProps.show) {
14
      this.setState({ style: {} });
15
    } else if (this.props.show && !newProps.show) { // true => false
16
      // set display to 'none' after 1 sec (for fade-out animation)
17
      setTimeout(() => this.setState({ style: { display: 'none' } }), 1000);
18
    }
19
  }
20
21
  render() {
22
    return <div className={`loading-backdrop fade ${this.props.show ? 'in' : ''}`} style={this.state.style}><div className="loading" /></div>;
23
  }
24
}
25
26
Loading.defaultProps = {
27
  show: false,
28
};
29
30
Loading.propTypes = {
31
  show: PropTypes.bool,
32
};
33